from urllib.request import *
from urllib.parse import *
from fake_useragent import *

# Get请求的参数都是在Url中体现的,如果有中文，需要转码,这时我们可使用
# urllib.parse.quote()
# urllib.parse.urlencode()
# url = f'https://www.baidu.com/s?{urlencode({"wd": "编程", "ie": "utf-8"})}'
url = f'https://www.baidu.com/s?wd={quote("编程")}'

# 获取fake_useragent库中的UserAgent
agent = UserAgent()

headers = {
    "User-agent": agent.chrome
}

request = Request(url, headers=headers)

response = urlopen(request)

info = response.read()

print(info.decode())
